package com.example.ordersystem.controller;

import com.example.ordersystem.entity.Dish;
import com.example.ordersystem.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/dishes")
public class DishController {
    @Autowired
    private DishService dishService;

    @GetMapping
    public String listDishes(@RequestParam(value = "category", required = false) String category, Model model) {
        model.addAttribute("categories", dishService.getAllCategories());
        if (category != null && !category.isEmpty()) {
            model.addAttribute("dishes", dishService.getDishesByCategory(category));
            model.addAttribute("selectedCategory", category);
        } else {
            model.addAttribute("dishes", dishService.getAllDishes());
            model.addAttribute("selectedCategory", "");
        }
        return "menu";
    }

    @GetMapping("/{id}")
    public String getDish(@PathVariable Long id, Model model) {
        model.addAttribute("dish", dishService.getDishById(id));
        return "dish-detail";
    }
} 